package org.pattern.builder.builders.readers;

import org.pattern.builder.builders.readers.PizzaFileReader;
import org.pattern.builder.model.PizzaPropertyNames;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 16-11-2010
 * Time: 18:50:46
 * To change this template use File | Settings | File Templates.
 */
public class PizzaPropertiesFileReader extends PizzaFileReader {

    private Properties props = null;

    public String getProperty(String property) {
        InputStream inputStream = null;
        if (props == null) {
            try {
                inputStream = getClass().getResourceAsStream (getFilename());                
                if (inputStream != null){
                    props = new Properties();
                    props.load(inputStream);
                }
                else
                   throw new Exception("file not found");
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }finally{
                if (inputStream != null )
                    try{
                        inputStream.close();
                    } catch (IOException e) {
                    e.printStackTrace();  
                    System.exit(1);
                }


            }
        }
        return props.getProperty(property);
    }
}
